import md5 from 'js-md5';

var rnd = '', timestamp = '';

function r_key() {
    rnd = Math.random().toString(36).substr(2);
    var timestamp = Date.parse(new Date());
    timestamp = timestamp / 1000;
    //timestamp = gettime();
    var url = rnd
    //var rnt = (timestamp+url).substring(7, 18)
    return timestamp+url
}

function p_key() {
    var timestamp = Date.parse(new Date());
    timestamp = timestamp / 1000;
    var url = rnd;
    var rnt = (timestamp+url).substring(7, 18)
    //return timestamp+url
    //return md5(rnt)
    return md5(md5(rnt)+md5(url))
}

function rePhone(phone) {
    var result = '';
    if (phone.length >= 11) {
        result = phone.substring(0, 3) + '****' + phone.substring(8, 11);
    } else {
        result = phone
    }
    return result;
}

var isMobile = {
    Android: function () {
        return navigator.userAgent.match(/Android/i);
    },
    BlackBerry: function () {
        return navigator.userAgent.match(/BlackBerry/i);
    },
    iOS: function () {
        return navigator.userAgent.match(/iPhone|iPad|iPod/i);
    },
    Opera: function () {
        return navigator.userAgent.match(/Opera Mini/i);
    },
    Windows: function () {
        return navigator.userAgent.match(/IEMobile/i);
    },
    any: function () {
        return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
    }
};


export default
{
  r_key,
  p_key,
  rePhone,
  isMobile
}
